*--------------------------------------------------------------------------------------------------------*
* Do shifts in late-counted votes signal fraud? Evidence from Bolivia		                             *
* Nicolás Idrobo, Dorothy Kronick, Francisco Rodríguez                                                   *
* Corresponding author: Dorothy Kronick (kronick@sas.upenn.edu)                                          *
* Last modification: 01/25/2022                                                                          *
* Version of Stata: Stata MP 15.1 2-cores                                                                *
* ------------------------------------------------------------------------------------------------------ *                    
* Additional programs (not written by us) needed:                                                        *
* 1.) rdrobust (https://rdpackages.github.io/rdrobust/) can be obtained by running:                      *
* net install rdrobust, from(https://raw.githubusercontent.com/rdpackages/rdrobust/master/stata) replace *
* 2.) binsreg (https://nppackages.github.io/binsreg/) can be obtained by running:                        *
* net install binsreg, from(https://raw.githubusercontent.com/nppackages/binsreg/master/stata) replace   *
* 3.) nprobust (https://nppackages.github.io/nprobust/) can be obtained by running                       *
* net install nprobust, from(https://raw.githubusercontent.com/nppackages/nprobust/master/stata) replace *
* 4.) semipar can be obtained by running "ssc install semipar, replace"                                  *
* 5.) estout can be obtained by running "ssc install estout, replace"                                    *
* 6.) reghdfe can be obtained by running "ssc install reghdfe, replace"                                  *
* 7.) ftools is needed by reghdfe. Can be obtained by running "ssc install ftools, replace"              *
* 8.) renvars can be obtained by running "findit renvars".                                               *
* 9.) geodist can be obtained by running "ssc install geodist, replace".                                 *
* 10.) levenshtein can be obtained by running:                                                           *
* net install strgroup, from(https://raw.githubusercontent.com/reifjulian/strgroup/master) replace       *
* 11.) outreg2 can be obtained by running "ssc install outreg2, replace"                                 *
* 12.) mmerge can be obtained by running "ssc install mmerge, replace"                                   *
* 13.) savesome can be obtained by running "ssc install savesome, replace"                               *
* ------------------------------------------------------------------------------------------------------ *
* Additional programs (written by us) needed:                                                            *
* 1.) rdrobust_export.ado is a program that exports the results from rdrobust to Latex.                  *
* 2.) myround.ado is a program that helps us round decimals before exporting results to Latex.           *
* 3.) superclean_basic.ado is a program that removes Spanish accents and standardizes strings.           *
* These programs are included in the codes/auxiliary_programs folder and are loaded on specific          *
* do-files as needed.                                                                                    *
*--------------------------------------------------------------------------------------------------------*

*------------------------------*
* 1.) CHOOSE working directory *
*------------------------------*
* Define a working directory
* User should choose the directory where the folder was unzipped
cd "E:/Github/Bolivia/00_replication_files"
	
*-------------------*
* 2.) Preliminaries *
*-------------------*
clear
clear all
cap log close
set more off, perm
set seed 39975195
set matsize 2000

* Number of RD sortings
global rdreps 1000

* Deleting generated data files, output files, and log files,
* so that everything is freshly produced.
foreach x in "data/outputs" "outputs/generated" "log-files" {
	local files: dir "`x'" files *
	foreach file of local files {
	        rm "`x'/`file'"
	}
}

*---------------------*
* 3.) Data generation *
*---------------------*
	* Code that uses the raw data in data/inputs to produce the
	* intermediate data sets that we use in the analysis.
	do "codes/1_Data_part1_initialsetup.do"

*-------------*
* 4.) Figures *
*-------------*
	* Define the list of control variables that are used throughout the paper
	# delimit ;
		global controls "ln_density ln_aglabor logpop ln_dist_capital 
			capital_depto medialuna Inscritos";

		global controls_educ "ln_density ln_aglabor logpop ln_dist_capital 
			capital_depto medialuna Inscritos
			analfabetismo ed_prim ed_sec";
	# delimit cr

	* Run code to produce figures
	foreach x in F1 1 2 3 A1 A2 A3 B1 C1 D1 D3 H3 H4 {
		do "codes/2_Figure_`x'.do"
	}

*------------*
* 5.) Tables *
*------------*
	foreach x in 1 B1 D1 E1 F1 F2 {
		do "codes/3_Table_`x'.do"
	}

*------------------------------------------------------------------------------*
clear all
